package com.gopay.bis.manager.bank.fund;

import com.gopay.common.FundResult;
import com.gopay.common.domain.fund.vo.PageData;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.FundManagerRemoteService;
import com.gopay.remote.bank.businesses.FundService;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 中信基金管理器
 * @CiticFundManager.java
 * @author wangdong
 * @2016-4-29 下午1:48:47 www.gopay.com.cn Inc.All rights reserved.
 */
public class CiticFundManager implements FundManagerRemoteService {

	@Resource(name = "citicConfig")
	private Map<String, String> citicConfig;
	
	@Resource(name = "citicFundServiceClient")
	private FundService citicFundServiceClient;
	
	private final static String XML_HEADER = "<?xml version=\"1.0\" encoding=\"GB2312\" ?>";

	@Override
	public boolean verify(PageData pageData) throws GopayException {
		return citicFundServiceClient.verify(pageData);
	}

	@Override
	public FundResult send(PageData pageData) throws GopayException {
		return citicFundServiceClient.send(pageData);
	}

	/**
	 * 构建明文信息
	 * 
	 * @param message
	 * @return
	 */
	private String buildPlain(Object message) {
		XStream xs = new XStream(new DomDriver());
		xs.autodetectAnnotations(true);
		String plain = xs.toXML(message);
		StringBuffer xml = new StringBuffer(XML_HEADER);
		xml.append(plain);
		String fullXml = xml.toString();
		fullXml = fullXml.replaceAll("\n", "").replaceAll("\r", "");
		return fullXml;
	}

}
